
package com.ce.cases.check.action;


import java.io.IOException;
import java.util.Date;
import java.util.List;

import org.jsoup.helper.StringUtil;

import com.ce.cases.check.dao.po.CaseCheckEnterprice;
import com.ce.cases.check.dao.po.CaseEnterpriceInfo;
import com.ce.cases.check.dao.po.CaseSourceCheck;
import com.ce.cases.check.logic.ICaseCheckLogic;
import com.ce.cases.source.dao.po.CaseSource;
import com.ce.cases.source.dao.po.CaseSourceFiles;
import com.ce.framework.datamaintain.action.DataMaintainAction;
import com.ce.framework.exception.AppException;
import com.ce.framework.util.BeanAccessUtil;
import com.ce.framework.util.DateUtil;
import com.ce.framework.util.GeneratorUUID;
import com.ce.sys.dict.dao.po.SysDictItem;
import com.ce.sys.login.model.User;
import com.ce.util.DictUtil;
import com.ce.util.FlowWorkUtil;
import com.ce.util.NetFileUtil;
import com.ce.workflow.work.dao.po.WorkflowFlow;

/**
* 嫦娥软件有限公司 版权所有 2013
* 创建人：　andy
* 创建日期：2014-03-28
* 创建时间：10:28:20
* 功能描述：检查情况登记 [CASE_SOURCE_CHECK]更改时用的Action
* ==============================================
* 修改历史
* 修改人		修改时间		修改原因
*
* ==============================================
*/
public class CaseSourceCheckAction extends DataMaintainAction 
{
	private static final long serialVersionUID = 1L;
	
	private ICaseCheckLogic  caseCheckLogic;
	private CaseCheckEnterprice entPo;
	/**
	 * 检查情况登记页
	 */
	@SuppressWarnings("unchecked")
	public String checkRegPage(){
		String caseId = this.getSelectId();
		
		WorkflowFlow flowing=FlowWorkUtil.getWorkflowFlowByPersonCling(caseId, User.getUserId());//当前人正在处理的节点
		if(flowing==null||flowing.getVcSequence()!=2){
			return this.alertMsgAndExecJs("检查环节已不能进行该操作", "$('#operateWindow').window('close');");
		}
		
		try {
			List<CaseSourceCheck> checkRegList = (List<CaseSourceCheck>) this.baselogic
					.searchByHql("From CaseSourceCheck po where po.caseId='"+ caseId + "'");
			if (!checkRegList.isEmpty()) {
				po = checkRegList.get(0);
			}else{
			   BeanAccessUtil.copyProperty(po, "caseId", caseId);
               BeanAccessUtil.copyProperty(po, "registerDeptId", User.getUserOrgId());
               BeanAccessUtil.copyProperty(po, "registerPerson", User.getUserName());
               BeanAccessUtil.copyProperty(po, "registerDate", new Date());
			}
			List<SysDictItem> itemList=DictUtil.getDictListByName("检查案源台账-采取措施");
			this.setAttribute("itemList", itemList);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "checkRegisterPage";
	}
	/**
	 * 检查情况登记保存
	 */
	public String checkRegister() {
		try {
			//添加
			if (StringUtil.isBlank(po.getVcId())) {
				po.setVcId(GeneratorUUID.generateUUID());
				this.baselogic.addPo(po);
			} else {//修改
				this.baselogic.updatePo(po);
			}
		} catch (AppException e) {
			e.printStackTrace();
			return this.returnInfoForJS(false, e.getMessage());
		}
		return this.returnInfoForJS(true, "检查情况登记成功！");
	}
	/**
	 * 检查对象基本情况页
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String checkEntPage(){
		String caseId=this.getSelectId();
		try {
			List<CaseCheckEnterprice> entList = (List<CaseCheckEnterprice>) this.baselogic
					.searchByHql("From CaseCheckEnterprice po where po.caseId='"+ caseId + "'");
			if(!entList.isEmpty()){
				entPo=entList.get(0);
				List<CaseEnterpriceInfo> infoList1=caseCheckLogic.getCaseEnterpriceInfoByFlag(entPo.getVcId(), 1);
				List<CaseEnterpriceInfo> infoList2=caseCheckLogic.getCaseEnterpriceInfoByFlag(entPo.getVcId(), 2);
				List<CaseEnterpriceInfo> infoList3=caseCheckLogic.getCaseEnterpriceInfoByFlag(entPo.getVcId(), 3);
				this.setAttribute("infoList1", infoList1);
				this.setAttribute("infoList2", infoList2);
				this.setAttribute("infoList3", infoList3);
			}else{
				entPo.setCaseId(caseId);
			}
		} catch (AppException e) {
			e.printStackTrace();
		}
		return "checkEnterpriceEdit";
	}
	/**
	 * 保存检查对象基本情况
	 * @return
	 */
	public String checkEntReg(){
		caseCheckLogic.dealEnterpriceInfo(entPo,investors, investmentsRate,
				   year, mainIncome, mainCost, addedTax, incomeTax, 
				   dealDate, illegalResult, overdueTax, fine);
		
		return this.returnInfoForJS(true, "保存成功！");
	}
	public String showCaseSourceFile(){
		String vcId=this.getParameter("chkSelf");
		String vcType=this.getParameter("vcType");
		String vcFileId=this.getParameter("vcFileId");
		String vcFileName=this.getParameter("fileName");
		String fileType="";
		if(vcFileName.contains("."))
			fileType=vcFileName.substring(vcFileName.indexOf("."), vcFileName.length());
		this.setAttribute("fileType", fileType);
		this.setAttribute("vcFileName", vcFileName);
		String filePath="";
		try {
			filePath=NetFileUtil.getFileServerPath(vcFileId);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		this.setAttribute("filePath", filePath);
		return "showCaseSourceFile";
	}
	//上传文书
	public String checkNoticePage(){
		String vcId=this.getParameter("chkSelf");
		String fileType=this.getParameter("fileType");
		WorkflowFlow flowing=FlowWorkUtil.getWorkflowFlowByPersonCling(vcId, User.getUserId());//当前人正在处理的节点
		if(flowing==null||flowing.getVcSequence()!=2){
			return this.alertMsgAndExecJs("检查环节已不能进行该操作", "$('#operateWindow').window('close');");
		}
		CaseSource casePo=null;
		try {
			casePo=(CaseSource) this.baselogic.getPOByPk(CaseSource.class.getName(), vcId);
		} catch (AppException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		this.setAttribute("po", casePo);
		this.setAttribute("fileType", fileType);
		this.setAttribute("userName", User.getUserName());
		this.setAttribute("dtDate", DateUtil.format(new Date(), "yyyy年MM月dd日"));
		return "caseCheckNoticePage";
	}
	/*
	 * 提请审批操作
	 */
	public String addCheckNotice() throws AppException{
		String vcRecordId=this.getParameter("vcRecordId");
		String vcFileId=this.getParameter("fileId");
		String vcFileName=this.getParameter("fileName");
		WorkflowFlow flow=FlowWorkUtil.getWorkflowFlowByVcSeq(vcRecordId, "2");
		CaseSourceFiles file=new CaseSourceFiles();
		file.setVcId(GeneratorUUID.generateUUID());
		file.setDtDate(new Date());
		file.setVcDelFlag("0");
		file.setVcOrgId(User.getUserOrgId());
		file.setVcOrgName(User.getUserOrgName());
		file.setVcPersonId(User.getUserId());
		file.setVcPersonName(User.getUserName());
		file.setVcFileId(vcFileId);
		file.setVcFileName(vcFileName);
		file.setVcRecordId(vcRecordId);
		if(flow!=null)
			file.setVcFlowId(flow.getVcId());
		baselogic.addPo(file);
		FlowWorkUtil.saveWorkflowMan(vcRecordId,"上传"+vcFileName);
		return this.returnInfoForJS(true, "上传成功!");
	}
	public ICaseCheckLogic getCaseCheckLogic() {
		return caseCheckLogic;
	}
	public void setCaseCheckLogic(ICaseCheckLogic caseCheckLogic) {
		this.caseCheckLogic = caseCheckLogic;
	}
	public CaseCheckEnterprice getEntPo() {
		return entPo;
	}
	public void setEntPo(CaseCheckEnterprice entPo) {
		this.entPo = entPo;
	}
    private String[] investors;
    private Double[] investmentsRate;
    private Integer[] year;
    private Double[] mainIncome;
    private Double[] mainCost;
    private Double[] addedTax;
    private Double[] incomeTax;
    private Date[]   dealDate;
    private String[] illegalResult;
    private Double[] overdueTax;
    private Double[]  fine;
	public String[] getInvestors() {
		return investors;
	}
	public void setInvestors(String[] investors) {
		this.investors = investors;
	}
	public Double[] getInvestmentsRate() {
		return investmentsRate;
	}
	public void setInvestmentsRate(Double[] investmentsRate) {
		this.investmentsRate = investmentsRate;
	}
	public Integer[] getYear() {
		return year;
	}
	public void setYear(Integer[] year) {
		this.year = year;
	}
	public Double[] getMainIncome() {
		return mainIncome;
	}
	public void setMainIncome(Double[] mainIncome) {
		this.mainIncome = mainIncome;
	}
	public Double[] getMainCost() {
		return mainCost;
	}
	public void setMainCost(Double[] mainCost) {
		this.mainCost = mainCost;
	}
	public Double[] getAddedTax() {
		return addedTax;
	}
	public void setAddedTax(Double[] addedTax) {
		this.addedTax = addedTax;
	}
	public Double[] getIncomeTax() {
		return incomeTax;
	}
	public void setIncomeTax(Double[] incomeTax) {
		this.incomeTax = incomeTax;
	}
	public Date[] getDealDate() {
		return dealDate;
	}
	public void setDealDate(Date[] dealDate) {
		this.dealDate = dealDate;
	}
	public String[] getIllegalResult() {
		return illegalResult;
	}
	public void setIllegalResult(String[] illegalResult) {
		this.illegalResult = illegalResult;
	}
	public Double[] getOverdueTax() {
		return overdueTax;
	}
	public void setOverdueTax(Double[] overdueTax) {
		this.overdueTax = overdueTax;
	}
	public Double[] getFine() {
		return fine;
	}
	public void setFine(Double[] fine) {
		this.fine = fine;
	}
	
}

